<?php
$tr = Zend_Registry::get('Zend_Translate');
$db = Zend_Registry::get('DB');

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
{
  $ssl_enabled = true;
}
else
{
  $ssl_enabled = false;
}

echo "\x3c?xml version=\"1.0\" encoding=\"UTF-8\"?\x3e\n";
echo $this->doctype() . "\n";
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
XoNoiD CRM
-->
<head>
  <link rel="icon" type="image/png" href="<?php echo $this->baseUrl();?>/images/favicon.png" />
  <title>XoNoiD CRM</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
echo $this->headLink()->appendStylesheet($this->baseUrl() . '/css/');

// Dojo
if ($this->dojo()->isEnabled())
{
  $this->dojo()->setLocalPath('/javascript/dojo/dojo.js');
  $this->dojo()->addStyleSheetModule('dijit.themes.tundra');
  $this->dojo()->requireModule('dijit._editor.plugins.LinkDialog');
  $this->dojo()->requireModule('dijit._editor.plugins.FontChoice');
  $this->dojo()->requireModule('dijit._editor.plugins.EnterKeyHandling');

  echo $this->dojo();
}
?>
</head>
<body class="tundra">
  <h1 style="position: absolute; float:left; right:1em; top:0.2em; color: #222;">XoNoiD CRM</h1>

  <div id="menu">
    <a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'index'), '', true); ?>"><img src="<?php echo $this->baseUrl();?>/images/icons/frontpage.png" alt="" border="0" /></a>
    <a href="<?php echo $this->url(array('controller' => 'user', 'action' => 'index'), '', true); ?>"><img src="<?php echo $this->baseUrl();?>/images/icons/users.png" alt="" border="0" /></a>
    <a href="<?php echo $this->url(array('controller' => 'company', 'action' => 'index'), '', true); ?>"><img src="<?php echo $this->baseUrl();?>/images/icons/customers.png" alt="" border="0" /></a>
    <a href="<?php echo $this->url(array('controller' => 'ticket', 'action' => 'index'), '', true); ?>"><img src="<?php echo $this->baseUrl();?>/images/icons/tickets.png" alt="" border="0" /></a>
    <a href="<?php echo $this->url(array('controller' => 'index', 'action' => 'logout'), '', true); ?>"><img src="<?php echo $this->baseUrl();?>/images/icons/logout.png" alt="" border="0" /></a>
  </div>

  <hr />

  <!-- CONTENT -->
  <div id="content">
    <?php echo $this->layout()->content; ?>
  </div>
  <!-- /CONTENT -->

  <br />
  
  <hr />
  <br />

<div id="footer">
  <a href="http://code.google.com/p/xonoid/">XoNoiD CRM</a> &copy; Pekka Järvinen 2008- | <span id="ssl-status-<?php echo ($ssl_enabled ? 'on' : 'off');?>"><abbr title="<?php echo $tr->_("Secure Socket Layer");?>"><?php echo $tr->_("SSL");?></abbr> <?php echo $tr->_("Encryption:");?> <?php echo ($ssl_enabled ? $tr->_("Enabled") : $tr->_("Disabled"));?></span>
  <a href="http://framework.zend.com/"><img src="<?php echo $this->baseUrl();?>/images/misc/PoweredBy_ZF_4LightBG.png" alt="" border="0" /></a><br />

<br />

<div id="page-stats">
<small><?php
$profiler = $db->getProfiler();

$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();

echo sprintf($tr->_("Executed %s SQL queries in %s seconds"), $queryCount, round($totalTime, 3));
?></small>
 | 
<small><?php 
echo sprintf($tr->_("Rendered in %s seconds"), round(microtime(true) - SCRIPT_START_TIME, 3));
?></small>
 | 
<small><?php 
echo sprintf($tr->_("Version %s"), VERSION);
echo " ";

$version_cache_time = 60*60*24; // Cache time in seconds

$LATEST_VERSION_FILE = CACHE_DIRECTORY . '/LATEST_VERSION';

clearstatcache();

if (!file_exists($LATEST_VERSION_FILE))
{
  file_put_contents($LATEST_VERSION_FILE, VERSION);
  @chmod($LATEST_VERSION_FILE, 0777);
  @touch($LATEST_VERSION_FILE, 1, 1);
}

if (file_exists($LATEST_VERSION_FILE))
{
  // Cache expired
  if (filemtime($LATEST_VERSION_FILE) < (time() - $version_cache_time))
  {
    $data = file_get_contents('http://xonoid.googlecode.com/svn/wiki/VERSION.wiki');
  
    // Error getting version
    if ($data === false)
    {
      // Read from cache..
    }
    else
    {
      $data = trim($data);

      // valid digit.digit.digit format
      if (preg_match("/^\d+\.\d+\.\d+$/", $data))
      {
        file_put_contents($LATEST_VERSION_FILE, $data);
        @touch($LATEST_VERSION_FILE, time(), time());
      }
    }

  }

  $LATEST_VERSION = file_get_contents($LATEST_VERSION_FILE);

  if (version_compare(VERSION, $LATEST_VERSION) === -1)
  {
    echo " ";
    echo sprintf($tr->_("New version %s is available!"), $LATEST_VERSION);
  }
}
?></small>
</div>

</div>

<br />

</body>
</html>
